<%@page import="io.github.ilkgunel.pojo.Record"%>
<%@ page import="java.util.Iterator" %>
<%@ page import="io.github.ilkgunel.pojo.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="io.github.ilkgunel.dao.test2_1" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>


<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <link rel="shortcut icon" href="favicon.ico"> <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/plugins/codemirror/codemirror.css" rel="stylesheet">
    <link href="css/plugins/codemirror/ambiance.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body>
<%
    List<Student> list = null;
    test2_1 dao=new test2_1();
    list=dao.find();
    if(list==null){
%>
 <script>
     alert("kongla")
 </script>
<%
}
%>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>test2.1找出年龄小于20岁的所有学生</h5>

                </div>
                <div class="ibox-content">

                    <table class="table table-striped table-bordered table-hover dataTables-example">
                        <thead>
                        <tr>
                            <th>学号</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>年龄</th>
                            <th>出生日期</th>
                            <th>院系名称</th>
                            <th>班级</th>

                        </tr>
                        </thead>
                        <tbody>
                        <%

                            Student student=null;
                            if(list!=null&&list.size()!=0){

                                for(int i=0;i<list.size();i++) {
                                    student = list.get(i);


                        %>
                        <tr class="gradeX">
                            <td><%=student.getSid()%>
                            <td><%=student.getName()%>
                            <td><%=student.getSex()%>
                            </td>
                            <td><%=student.getAge()%></td>
                            <td><%=student.getBirthday()%></td>
                            <td class="center"><%=student.getDname()%></td>
                            <td class="center"><%=student.getTheclass()%></td>


                        </tr>
                        <%}}
                        %>

                        </tbody>

                    </table>

                </div>
            </div>
        </div>
    </div>

</div>

<%--代码部分--%>
<div class="wrapper wrapper-content  animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>实验关键代码</h5>
                </div>
                <div class="ibox-content">

                    <p class="m-b-lg">
                        <strong>Dao包  </strong>test2_2
                    </p>

                    <textarea id="code1">
public class test2_1 {
    public List<Student> find()
    {
        List<Student> list = new ArrayList<>();
        AccessMongoDB accessMongoDB = new AccessMongoDB();


        Document filter = new Document();
        //小于 20岁的
         filter.append("age",new Document("$lt", 20));
        FindIterable<Document> result = accessMongoDB.getCollection("student").find(filter);


        MongoCursor<Document> cursor = result.iterator();
        while (cursor.hasNext()) {

            Document document = cursor.next();

            Student s=new Student();
            s.set_id(document.get("_id").toString());

            s.setSid( new BigDecimal((document.get("sid")).toString()).toPlainString());
            s.setName(document.get("name").toString());
            s.setSex( document.get("sex").toString());

            String temp= new BigDecimal((document.get("age")).toString()).toPlainString();
            s.setAge((int)Double.parseDouble( temp));

            s.setBirthday( document.get("birthday").toString());
            s.setDname( document.get("dname").toString());

            temp= new BigDecimal((document.get("class")).toString()).toPlainString();
            s.setTheclass((int) Double.parseDouble( temp));

            list.add(s);
        }
        return list;
    }
}
</textarea>
                </div>
            </div>
        </div>

    </div>
</div>
<br>


<a href="<c:url value="dataInsert"></c:url>">添加</a>
<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<!-- Peity -->
<script src="js/plugins/peity/jquery.peity.min.js"></script>

<!-- CodeMirror -->
<script src="js/plugins/codemirror/codemirror.js"></script>
<script src="js/plugins/codemirror/mode/javascript/javascript.js"></script>

<%----%>
<script src="js/plugins/jeditable/jquery.jeditable.js"></script>

<!-- Data Tables -->
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<!-- 自定义js -->
<script src="js/content.js?v=1.0.0"></script>

<script>
    $(document).ready(function () {

        var editor_one = CodeMirror.fromTextArea(document.getElementById("code1"), {
            lineNumbers: true,
            matchBrackets: true,
            styleActiveLine: true,
            theme: "ambiance"
        });

        var editor_two = CodeMirror.fromTextArea(document.getElementById("code2"), {
            lineNumbers: true,
            matchBrackets: true,
            styleActiveLine: true
        });


        $('.dataTables-example').dataTable();

        /* Init DataTables */
        var oTable = $('#editable').dataTable();

        /* Apply the jEditable handlers to the table */
        oTable.$('td').editable('../example_ajax.php', {
            "callback": function (sValue, y) {
                var aPos = oTable.fnGetPosition(this);
                oTable.fnUpdate(sValue, aPos[0], aPos[1]);
            },
            "submitdata": function (value, settings) {
                return {
                    "row_id": this.parentNode.getAttribute('id'),
                    "column": oTable.fnGetPosition(this)[2]
                };
            },

            "width": "90%",
            "height": "100%"
        });

    });


    function fnClickAddRow() {
        $('#editable').dataTable().fnAddData([
            "Custom row",
            "New row",
            "New row",
            "New row",
            "New row"]);

    }

</script>
</body>
</html>
